Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evm state override #2623

Merged
merged 5 commits into from
Jan 5, 2024
Merged

Evm state override #2623

merged 5 commits into from
Jan 5, 2024

Conversation

Jouzo
Copy link
Collaborator

@Jouzo Jouzo commented Oct 25, 2023

Summary

This PR adds support for overriding the contract code, storage, account balance and nonce for simulations with eth_call and eth_estimateGas. This feature is similarly supported by geth.

The eth_call RPC method now accepts a third override parameter which is a map from an address to the desired state of that address. The state object has the following keys, all of which are optional:

balance: QUANTITY - The balance to set for the account before executing the call.
nonce: QUANTITY - The nonce to set for the account before executing the call.
code: DATA - The EVM bytecode to set for the account before executing the call.
state*: OBJECT - Key-value mapping of storage slot to value that will clear all slots and then override individual slots in the account storage before executing the call.
stateDiff*: OBJECT - Key-value mapping of storage slot to value that will override individual slots in the account storage before executing the call.
*Note - stateDiff is either applied to state or existing state

So, an example override object using all fields overriding multiple addresses could look like the following:

{
  "0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3": { 
    "nonce": "0xa", 
    "balance": "0xffff", 
    "state": { 
      "0000000000000000000000000000000000000000000000000000000000000001": "0xbaddad42baddad42baddad42baddad42baddad42baddad42baddad42baddad42"
    } 
  },
  "0xebe8efa441b9302a0d7eaecc277c09d20d684540": { 
    "code": "0x123456", 
    "stateDiff": {
      "0000000000000000000000000000000000000000000000000000000000000002": "0xbaddad42baddad42baddad42baddad42baddad42baddad42baddad42baddad42"
    } 
  }
}

Like all state changes made with eth_call and eth_estimateGas, the changes are ephemeral and only last for that specific run.

Fixes #2122

@Jouzo Jouzo force-pushed the evm_state_override branch from 2f4bdfe to bd1629b Compare November 6, 2023 08:16
@Jouzo Jouzo force-pushed the evm_state_override branch from bd1629b to 4765987 Compare November 6, 2023 08:18
@Jouzo Jouzo marked this pull request as ready for review November 20, 2023 14:28
sieniven
sieniven previously approved these changes Nov 22, 2023
@Jouzo Jouzo merged commit 9e8e223 into master Jan 5, 2024
15 of 16 checks passed
@Jouzo Jouzo deleted the evm_state_override branch January 5, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add State Override Support for eth_call
2 participants